package com.graficas;

import java.util.ArrayList;

import org.achartengine.ChartFactory;
import org.achartengine.GraphicalView;
import org.achartengine.chart.PointStyle;
import org.achartengine.model.TimeSeries;
import org.achartengine.model.XYMultipleSeriesDataset;
import org.achartengine.renderer.XYMultipleSeriesRenderer;
import org.achartengine.renderer.XYSeriesRenderer;

import android.content.Context;
import android.content.Intent;
import android.graphics.Color;

public class LineGraph {
	
	//private  int[] x = null; 
    //private  int[] y = null;
	private ArrayList<Float> x1 = null;
	private ArrayList<Float> y1 = null;
	private ArrayList<Float> x2 = null;
	private ArrayList<Float> y2 = null;
	private ArrayList<Float> x3 = null;
	private ArrayList<Float> y3 = null;
	private ArrayList<Float> x4 = null;
	private ArrayList<Float> y4 = null;
    //public GraphicalView getIntent(Context context, int x1[],int y2[]){
    public GraphicalView getIntent(Context context, ArrayList<Float> xCosto,ArrayList<Float> yCosto, 
    		ArrayList<Float> xAsist1,ArrayList<Float> yAsist1, 
    		ArrayList<Float> xAsist2,ArrayList<Float> yAsist2, 
    		ArrayList<Float> xAsist3,ArrayList<Float> yAsist3,
    		float totalAforo){
//    	GraphicalView mChartView = null;
      
        
        x1 = xCosto; 
        y1 = yCosto;
        
        this.x2 = xAsist1; 
        this.y2 = yAsist1;
        
        this.x3 = xAsist2; 
        this.y3 = yAsist2;
        
        this.x4 = xAsist3; 
        this.y4 = yAsist3;
        
        
        TimeSeries series = new TimeSeries("Punto Equilibrio");
        for (int i=0;i<x1.size();i++){
            series.add(x1.get(i),y1.get(i));
        }

//        int[] x2 = {3,4,5,6,7,8,9,10,12,15}; 
//        int[] y2 = {172,123,162,152,149,122,110,120,125,155};

        TimeSeries series2 = new TimeSeries(Math.round(y2.get(0)*100/totalAforo)+"% Asist");
        for (int i=0;i<this.x2.size();i++){
            series2.add(this.x2.get(i),y2.get(i));
        }

        TimeSeries series3 = new TimeSeries(Math.round(y3.get(0)*100/totalAforo)+"% Asist");
        for (int i=0;i<this.x3.size();i++){
            series3.add(this.x3.get(i),y3.get(i));
        }
        
        TimeSeries series4 = new TimeSeries(Math.round(y4.get(0)*100/totalAforo)+"% Asist");
        for (int i=0;i<this.x4.size();i++){
            series4.add(this.x4.get(i),y4.get(i));
        }

        XYMultipleSeriesDataset dataset = new XYMultipleSeriesDataset();
        dataset.addSeries(series);
        dataset.addSeries(series2);
        dataset.addSeries(series3);
        dataset.addSeries(series4);


        XYSeriesRenderer renderer = new XYSeriesRenderer();
        renderer.setColor(Color.rgb(141,166,189));
        renderer.setPointStyle(PointStyle.SQUARE);
        renderer.setFillPoints(true);
        renderer.setLineWidth(3);
        renderer.setDisplayChartValues(true);

        XYSeriesRenderer renderer2 = new XYSeriesRenderer();
        renderer2.setColor(Color.WHITE);
        renderer2.setPointStyle(PointStyle.SQUARE);
        renderer2.setFillPoints(true);
        renderer2.setLineWidth(3);
        renderer2.setDisplayChartValues(true);
        
        XYSeriesRenderer renderer3 = new XYSeriesRenderer();
        renderer3.setColor(Color.LTGRAY);
        renderer3.setPointStyle(PointStyle.SQUARE);
        renderer3.setFillPoints(true);
        renderer3.setLineWidth(3);
        renderer3.setDisplayChartValues(true);
        
        XYSeriesRenderer renderer4 = new XYSeriesRenderer();
        renderer4.setColor(Color.GRAY);
        renderer4.setPointStyle(PointStyle.SQUARE);
        renderer4.setFillPoints(true);
        renderer4.setLineWidth(3);
        renderer4.setDisplayChartValues(true);

        XYMultipleSeriesRenderer mrenderer = new XYMultipleSeriesRenderer();
        mrenderer.addSeriesRenderer(renderer);
        mrenderer.addSeriesRenderer(renderer2);
        mrenderer.addSeriesRenderer(renderer3);
        mrenderer.addSeriesRenderer(renderer4);
        
        
        mrenderer.setChartTitle("Estimación de Evento");
        mrenderer.setBackgroundColor(Color.rgb(42, 43, 56));
        mrenderer.setShowGrid(true);
        mrenderer.setApplyBackgroundColor(true);
        mrenderer.setXTitle("Precio");
        mrenderer.setYTitle("Asistencia");
        mrenderer.setGridColor(Color.DKGRAY);
        //mrenderer.setMargins([1,1,1,1});
    //  mrenderer.setZoomButtonsVisible(true);
        
    	return ChartFactory.getLineChartView(context,dataset, mrenderer);

    }
}